package editornode

import (
	"fmt"
	"wails/modules/editor"
	"wails/modules/editor/routes"

	"gitee.com/zhongguo168a/go-nodex/dbx/mongox"
	"gitee.com/zhongguo168a/go-nodex/nodex"
	"gitee.com/zhongguo168a/go-nodex/nodex/models"
	"gitee.com/zhongguo168a/go-nodex/nodex/server/http"
	"gitee.com/zhongguo168a/go-nodex/nodex/server/ws"
)

func Run() {
	editor.Init()

	nodeConfig := &nodex.NodeConfig{
		Name: "example",
		PreServe: func() (err error) {
			return
		},
		Database: &mongox.Database{
			Name:   "nodex",
			Prefix: "example_",
			Addrs: []*mongox.Addr{
				{IP: "www.mywork.com", Port: "27017", User: "root", Pwd: "lJ3fB7vH2eW2iJ2e"},
			},
		},
		MsgQueue: &nodex.NsqMsgQueue{
			ProducerAddr: "mywork.com:4150",
			LookupdAddr:  "mywork.com:4161",
		},
		Channel:       "test",
		SerializeMode: nodex.JSON,
		Servers: []*models.ServerConfig{
			{
				Name: "ws",
				Host: "127.0.0.1",
				Port: "2100",
				Mode: ws.NAME,
			},
			{
				Name: "http",
				Host: "127.0.0.1",
				Port: "8080",
				Mode: http.NAME,
			},
		},

		RouteGroup: []*nodex.RouteGroupConfig{
			{
				AtServers:         []string{"http"},
				Name:              "editor",
				CallMode:          nodex.GOROUTINE,
				UseContextCreator: nil,
				RouteHandler:      &routes.Http{},
				EnableHttpGet:     false,
			},
		},
	}

	if err := nodex.Init(nodeConfig); err != nil {
		fmt.Println(err)
		return
	}
	runerr := nodex.Run()
	if runerr != nil {
		fmt.Println(runerr)
		return
	}
}
